package com.WaVel.service.impl;

import com.Emplyment.dto.StudyPathDto;
import com.Emplyment.entity.StudyPath;
import com.Emplyment.vo.StudyPathVo;
import com.WaVel.mapper.StudyPathMapper;
import com.WaVel.service.StudyRouteService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StudyRouteServiceImpl implements StudyRouteService {

    @Autowired
    private StudyPathMapper studyPathMapper;

    @Override
    public List<StudyPathVo> getAllStudies() {
        List<StudyPath> allStudies = studyPathMapper.getAllStudies();
        List<StudyPathVo> allStudiesVo = new ArrayList<>();
        for(StudyPath study: allStudies) {
            StudyPathVo vo = new StudyPathVo();
            BeanUtils.copyProperties(study, vo);
            allStudiesVo.add(vo);
        }
        return allStudiesVo;
    }

    @Override
    public void addStudy(StudyPathDto study) {
        StudyPath studyPath = new StudyPath();
        BeanUtils.copyProperties(study, studyPath);
        studyPathMapper.addStudy(studyPath);
    }

    @Override
    public void updateStudy(StudyPathDto dto) {
        StudyPath studyPath = new StudyPath();
        BeanUtils.copyProperties(dto, studyPath);
        studyPathMapper.updateStudy(studyPath);
    }

    @Override
    public void deleteStudy(int id) {
        studyPathMapper.deleteStudy(id);
    }
}
